
package org.springblade.modules.rate.feedback.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.rate.feedback.entity.Feedback;
import org.springblade.modules.rate.feedback.vo.FeedbackVO;
import org.springblade.modules.rate.feedback.service.IFeedbackService;
import org.springblade.core.boot.ctrl.BladeController;

/**
 * 反馈 控制器
 *
 * @author BladeX
 * @since 2021-10-10
 */
@RestController
@AllArgsConstructor
@RequestMapping("rate/feedback/feedback")
@Api(value = "反馈", tags = "反馈接口")
public class FeedbackController extends BladeController {

	private final IFeedbackService feedbackService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入feedback")
	public R<Feedback> detail(Feedback feedback) {
		Feedback detail = feedbackService.getOne(Condition.getQueryWrapper(feedback));
		return R.data(detail);
	}

	/**
	 * 分页 反馈
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "列表查询", notes = "传入feedback")
	public R<IPage<Feedback>> list(Feedback feedback, Query query) {
		IPage<Feedback> pages = feedbackService.page(Condition.getPage(query), Condition.getQueryWrapper(feedback));
		return R.data(pages);
	}

	/**
	 * 自定义分页 反馈
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入feedback")
	public R<IPage<FeedbackVO>> page(FeedbackVO feedback, Query query) {
		IPage<FeedbackVO> pages = feedbackService.selectFeedbackPage(Condition.getPage(query), feedback);
		return R.data(pages);
	}

	/**
	 * 新增 反馈
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入feedback")
	public R save(@Valid @RequestBody Feedback feedback) {
		return R.status(feedbackService.save(feedback));
	}

	/**
	 * 修改 反馈
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入feedback")
	public R update(@Valid @RequestBody Feedback feedback) {
		return R.status(feedbackService.updateById(feedback));
	}

	/**
	 * 新增或修改 反馈
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入feedback")
	public R submit(@Valid @RequestBody Feedback feedback) {
		return R.status(feedbackService.saveOrUpdate(feedback));
	}


	/**
	 * 删除 反馈
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(feedbackService.removeByIds(Func.toLongList(ids)));
	}


}
